import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:get/get.dart';
import 'package:mokeng/widgets/get_view_keep_alive.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import 'logic.dart';

class TransView extends GetViewKeepAlive {
  const TransView({super.key});

  @override
  Widget build(BuildContext context) {
    return GetX<TransController>(
      init: Get.put(TransController()),
      builder: (controller) => SmartRefresher(
        enablePullUp: true,
        physics: const BouncingScrollPhysics(),
        controller: controller.refreshController,
        onRefresh: controller.onRefresh,
        onLoading: controller.onLoading,
        child: MasonryGridView.count(
          padding: EdgeInsets.zero,
          crossAxisCount: 2,
          mainAxisSpacing: 4,
          crossAxisSpacing: 4,
          itemBuilder: (context, index) {
            var item = controller.newsList[index];
            return Image.network(
              item['coverPic'],
              height: 204 *
                  num.parse(item['coverHeight']) /
                  num.parse(item['coverWidth']),
              fit: BoxFit.cover,
            );
          },
          itemCount: controller.newsList.length,
        ),
      ),
    );
  }
}
